package com.sd365.permission.centre.api.controller;

import com.sd365.common.log.api.annotation.ApiLog;
import com.sd365.common.util.BeanUtil;
import com.sd365.permission.centre.api.BlackOrWhiteApi;
import com.sd365.permission.centre.pojo.dto.BlackOrWhiteDTO;
import com.sd365.permission.centre.pojo.query.BlackOrWhiteQuery;
import com.sd365.permission.centre.pojo.vo.BlackOrWhiteVO;
import com.sd365.permission.centre.service.BlackOrWhiteService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
public class BlackOrWhiteController implements BlackOrWhiteApi{
    @Resource
    BlackOrWhiteService blackOrWhiteService;

    @ApiLog
    @Override
    public List<BlackOrWhiteVO> commonQuery(BlackOrWhiteQuery blackOrWhiteQuery) {
        //执行查询
        List<BlackOrWhiteVO> blackOrWhiteVOS = blackOrWhiteService.commonQuery(blackOrWhiteQuery);

        return blackOrWhiteVOS;
    }
    @ApiLog
    @Override
    public Boolean batchUpdate(List<BlackOrWhiteDTO> blackOrWhiteDTOS) {
        return null;
    }

    @ApiLog
    @Override
    public Boolean add(BlackOrWhiteDTO blackOrWhiteDTO) {
        BlackOrWhiteVO add = blackOrWhiteService.add(blackOrWhiteDTO);
         if(!ObjectUtils.isEmpty(add)){
         return true;
         }else return false;
    }

    @ApiLog
    @Override
    public Boolean remove(Long id, Long version) {
        return blackOrWhiteService.remove(id,version);
    }

    @ApiLog
    @Override
    public Boolean batchDelete(@Valid BlackOrWhiteDTO[] blackOrWhiteDTOS) {
        return blackOrWhiteService.batchRemove(blackOrWhiteDTOS);
    }

    @ApiLog
    @Override
    public Boolean modify(@Valid BlackOrWhiteDTO blackOrWhiteDTO) {
        return blackOrWhiteService.modify(blackOrWhiteDTO);
    }

    @ApiLog
    @Override
    public BlackOrWhiteVO queryById(Long id) {
        BlackOrWhiteDTO blackOrWhiteDTO = blackOrWhiteService.queryById(id);
        if (blackOrWhiteDTO != null) {
            BlackOrWhiteVO blackOrWhiteVO= BeanUtil.copy(blackOrWhiteDTO,BlackOrWhiteVO.class);
            return blackOrWhiteVO;
        } else {
            return null;
        }
    }

    @ApiLog
    @Override
    public Boolean batchAdd(List<BlackOrWhiteDTO> blackOrWhiteDTOList){
        return blackOrWhiteService.batchAdd((blackOrWhiteDTOList));
    }

    @ApiLog
    @Override
    public BlackOrWhiteVO testRedis(BlackOrWhiteQuery blackOrWhiteQuery){
        return blackOrWhiteService.queryTest(blackOrWhiteQuery);
    }
}
